<?php
class PrintingController extends CController {

	const PAGE_SIZE = 10;

	public $project;

	public function filters() {
		return array (
			'ShowProject + index,list' // perform access control for CRUD operations
		);
	}
	
	public function filterShowProject($filterChain)
	{
		$project = Project::model()->findByPk($_GET['project_id']);
		if (!ProjectHelper::canReadProject($project))
		{
			throw new CHttpException(403,'Access Denied');
		}
		$filterChain->run();
	}

	public function init()
	{
		parent::init();
		if (isset($_GET['project_id']))
			$this->project = Project::model()->findByPk($_GET['project_id']);
	}

	public function accessRules() {
		return array (
			array (
				'allow', // allow all users to perform 'list' and 'show' actions
				'expression' => 'true'
			),
			array (
				'deny', // deny all users
				'users' => array (
					'*'
				)
			)
		);
	}

	public function actionIndex() {
		$this->redirect(array (
			'list'
		));
	}

	public function actionList() {
		$this->layout = 'project';
		$data = EditedReport::model()->findAll('project_id = :project_id', array(':project_id' => $_GET['project_id']));
		
		$reports = array();
		//$data = $data->getData();

		/*
		foreach ($data as $row)
		{
			$reports[$row->type][] = $row;
		}
		*/
		
		foreach ($data as $row) {
			if (!array_key_exists($row->report->title, $reports)) {
				$reports[$row->report->title] = array();
			}
			$reports[$row->report->title][] = $row;
		}
		
		$this->render('list', array (
			'reports' => $reports,
			'project' => $this->project
		));
	}

}
?>
